#include <iostream>
#include <cmath>
#include <vector>
#include <string>
using namespace std;

bool is_prime(int n) {
    if (n < 2) {
        return false;
    }
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    string input;
    getline(cin, input);
    vector<string> a;
    string word;
    for (char c : input) {
        if (c == ' ') {
            a.push_back(word);
            word.clear();
        } else {
            word += c;
        }
    }
    a.push_back(word);

    if (a.size() != 3) {
        cout << "Wrong input" <<endl;
        return 0;
    }

    vector<string> words = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    int s = 0;
    for (int i = 0; i < 3; i++) {
        bool found = false;
        for (int j = 0; j < 10; j++) {
            if (a[i] == words[j]) {
                if (i == 0) {
                    s = j * 100;
                } else if (i == 1) {
                    s += j * 10;
                } else {
                    s += j;
                }
                found = true;
                break;
            }
        }
        if (!found) {
            cout << "Wrong input" << endl;
            return 0;
        }
    }

    if (s >= 100) {
        int o = 0;
        while (true) {
            o++;
            if (is_prime(s - o)) {
                cout << s - o << endl;
                break;
            }
            if (is_prime(s + o)) {
                cout << s + o << endl;
                break;
            }
        }
    } 
    else {
        cout << "Wrong input" <<endl;
    }

    return 0;
}

